// 创建 Toast 容器
function createToastContainer() {
    let container = document.getElementById('toast-container');
    if (!container) {
        container = document.createElement('div');
        container.id = 'toast-container';
        container.className = 'position-fixed top-0 end-0 p-3';
        container.style.zIndex = '2080';
        document.body.appendChild(container);
    }
    return container;
}

// 显示 Toast 提示
function showToast(message, type = 'info') {
    const container = createToastContainer();
    const toast = document.createElement('div');
    
    // 设置 Toast 类型对应的颜色
    const typeClass = {
        'success': 'bg-success',
        'error': 'bg-danger',
        'warning': 'bg-warning',
        'info': 'bg-info'
    }[type] || 'bg-info';
    
    toast.className = `toast align-items-center text-white ${typeClass} border-0`;
    toast.setAttribute('role', 'alert');
    toast.setAttribute('aria-live', 'assertive');
    toast.setAttribute('aria-atomic', 'true');
    
    toast.innerHTML = `
        <div class="d-flex">
            <div class="toast-body">
                ${message}
            </div>
            <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
        </div>
    `;
    
    container.appendChild(toast);
    
    const bsToast = new bootstrap.Toast(toast, {
        autohide: true,
        delay: 3000
    });
    
    bsToast.show();
    
    // 监听隐藏事件，移除 DOM 元素
    toast.addEventListener('hidden.bs.toast', () => {
        toast.remove();
    });
}
